package com.huluobo.lib_http

import com.blankj.utilcode.util.SPUtils
import com.tencent.mmkv.MMKV
import com.zyj.retrofit.adapter.FlowCallAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 *  Created by LC on 2025/2/5.
 */
class TokenRetrofitImpl : BaseRetrofitImpl() {
    val mmkv = MMKV.defaultMMKV()
    override fun createRetrofit(): Retrofit {
        return Retrofit.Builder()
            .baseUrl(Const.BASE_URL)
            .client(
                createHttp()
                    .addInterceptor { chain ->
                        val request = chain.request()
                        val build = request.newBuilder().addHeader(
                            Const.PARAM_TOKEN,
                            mmkv.decodeString("token", "")!!
                        ).build()
                        chain.proceed(build)
                    }.build()

            )
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(FlowCallAdapterFactory.create())
            .build()
    }
}